<?php
class App_DbTable
{
	protected $_dbTable;
	protected $_row;
	
	public function __construct(Zend_Db_Table_Abstract $table, $id = null){
		$this->_dbTable = $table;
		if($id){
			$this->_row = $this->_dbTable->find($id)->current();
		}
		else{
			$this->_row = $this->_dbTable->createRow();
		}
	}
	public function __get($name){
		if(isset($this->_row->$name)){
			return $this->_row->$name;
		}
	}
	public function __set($name, $value){
		if(isset($this->_row->$name)){
			$this->_row->$name = $value;
		}
	}
	public function save(){
		$this->_row->save();
	}
	public function delete(){
		$this->_row->delete();
	}
	public function fill($data = array()){
		foreach ($data as $key => $value){
			//if($this->$key != $value)
			$this->$key = $value;
		}
	}
	public function getRow(){
		return $this->_row->toArray();
	}
	public function getAll(){
		return $this->_dbTable->fetchAll();
	}
}